package com.uft.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uft.service.TaskTracker;
import com.uft.utils.UftUtils;

@Controller
public class NotificationController {
	 @Autowired
	 private TaskTracker taskTracker;
	 private  static Logger  logger = Logger.getLogger(NotificationController.class);
	 
	 @RequestMapping(value="/getTaskDetails", method = RequestMethod.POST)
	 @ResponseBody
	 public String getTaskDetials(@RequestParam(value="uniqueID", required=true) String uniqueId,HttpServletRequest request){
		 String result="{";
		 logger.debug("uniqueID: "+uniqueId);
		 result+="\"UniqueId\":\""+uniqueId+"\"";
		 if(taskTracker.checkTaskExits(uniqueId)){
			 result+=",\"Result\":\""+UftUtils.TASK_EXIST+"\"";
			 String status=taskTracker.checkTaskStatus(uniqueId);
			 result+=",\"Status\":\""+status+"\"";
			 if(status.equalsIgnoreCase(UftUtils.TASK_COMPLETE)){
				 result+=",\"Output\":\""+taskTracker.getOutput(uniqueId)+"\"";
			 }
			 
		 }else{
			 result+=",\"Result\":\""+UftUtils.TASK_NOT_EXISTS+"\"";
			 result+=",\"Status\":\""+UftUtils.TASK_NOT_EXISTS+"\"";
		 }
		result+="}";
		logger.debug(result);
		 return result;
	 }
}
